﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insifo.WE;
using Microsoft.Reporting.WebForms;

public partial class repPreview : ObjectPage
{

    #region PROPIEDADES
    
    #endregion PROPIEDADES


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Cargar();
        }
    }

    protected void Cargar()
    {
        hfCodigoReporte.Value = Request.QueryString["i"];  // Codigo de reporte
        string pstrRutaReporte = HttpUtility.UrlDecode(Request.QueryString["r"]);  // Nombre de reporte
        ReportParameter[] ParametrosReporte = (ReportParameter[])Session[string.Format("ParametroReporte_{0}", hfCodigoReporte.Value)];
        MostrarReporte(rvReporte, ParametrosReporte, pstrRutaReporte);
    }

    protected void MostrarReporte(ReportViewer pRepView, ReportParameter[] pReparm, string pstrReporteRuta)
    {
        ServerReport srepServidor = pRepView.ServerReport;
        pRepView.ShowCredentialPrompts = false;
        RSCadenaConexion rs = new RSCadenaConexion();
        pRepView.ServerReport.ReportServerCredentials = new ReportCredentials(rs.UserId, rs.Password, rs.Domain);
        pRepView.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
        pRepView.ServerReport.ReportServerUrl = new System.Uri(rs.URLServer);
        pRepView.ServerReport.Timeout = rs.Timeout;
        pRepView.ServerReport.ReportPath = rs.Path + pstrReporteRuta;
        pRepView.ZoomMode = ZoomMode.Percent;
        pRepView.ZoomPercent = 100;
        pRepView.ShowParameterPrompts = false;
        if (pReparm != null && pReparm.Length > 0)
            pRepView.ServerReport.SetParameters(pReparm);

        pRepView.ServerReport.Refresh();
    }
}